package com.smart.controller;

import com.smart.common.ResultVo;
import com.smart.entity.All_Users;
import com.smart.entity.Users;
import com.smart.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/admin")
public class AdminUmsController {

    @Autowired
    UserService userService;

    @GetMapping("/ums/all")
    public ResultVo userall(Integer currentPage,Integer pageSize) {
        Map<String, Object> stringObjectMap = userService.UserAll(currentPage, pageSize);
        return ResultVo.ok().data("item", stringObjectMap);
    }

    @GetMapping("/ums/delete")
    public ResultVo userdelete(Long uid) {
        System.out.println(uid);
        Integer integer = userService.UserDelete(uid);
        return ResultVo.ok().data("item", integer);
    }

    @GetMapping("/ums/vip")
    public ResultVo uservip(Integer currentPage,Integer pageSize) {
        Map<String, Object> users = userService.UserVip(currentPage, pageSize);
        return ResultVo.ok().data("item", users);
    }

    @PostMapping("/ums/add")
    public ResultVo useradd(Users user) {
        userService.UserAdd(user);
        return ResultVo.ok().data("item", "users");
    }

    @GetMapping("/ums/user")
    public ResultVo user(String uid) {
        List<All_Users> user = userService.User(uid);
        return ResultVo.ok().data("item", user);
    }

    @PostMapping("/ums/edit")
    public ResultVo useredit(@RequestParam Map<String, String> user) {
        System.out.println(user);
        Integer result = userService.UserEdit(user);
        return ResultVo.ok().data("item", null );
    }

}
